package com.sun.showcase.controller.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import com.sun.showcase.biz.mall.service.SubjectService;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.client.domain.mall.Subject;
import com.sun.showcase.client.query.mall.SubjectQuery;

@Controller
@RequestMapping(value="/mall/subject") 
public class SubjectController{
	
	@Autowired
	private SubjectService subjectService;
	
	private Result result = new Result();
	/**
	 * 跳转到Subject管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goSubject")
	public String goSubject() {
		return "mall/subject";
	}
	/**
	 * 跳转到Subject新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleSubject")
	public String handleSubject(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "mall/subject_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public Subject showDesc(SubjectQuery subjectQuery) {
		return subjectService.get(subjectQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(SubjectQuery subjectQuery) {
		return subjectService.datagrid(subjectQuery);
	}
	

	/**
	 * 添加一个Subject
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(SubjectQuery subjectQuery) {
		subjectService.add(subjectQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑Subject
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(SubjectQuery subjectQuery) {
		subjectService.update(subjectQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除Subject
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(SubjectQuery subjectQuery) {
		subjectService.delete(subjectQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除Subject
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(SubjectQuery subjectQuery) {
		subjectService.deletePt(subjectQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据Subject
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(SubjectQuery subjectQuery) {
		List<SubjectQuery> list = subjectService.listAll(subjectQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
}
